package lambdademo;

import java.util.Comparator;
import java.util.PriorityQueue;


@FunctionalInterface
//函数式接口：只有一个抽象方法的接口
interface NoParameterNoReturn {
    void test();
}

//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}

//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}

//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}

//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}

//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}

public class TestDemo {

    public static void main4(String[] args) {
        PriorityQueue<Integer> minHeap = new PriorityQueue<>(3, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return 0;
            }
        });

        PriorityQueue<Integer> minHeap1 = new PriorityQueue<>(3, (o1,o2)->o1-o2);
    }

    public static void main3(String[] args) {
        NoParameterReturn noParameterReturn = ()->{return 10;};
        NoParameterReturn noParameterReturn2 = ()->10;

        OneParameterReturn oneParameterReturn = a->a+11;

        MoreParameterReturn moreParameterReturn = (a,b)->a+b;

    }

    public static void main2(String[] args) {
        int size = 10;
        size = 9;
        OneParameterNoReturn oneParameterNoReturn = (a)->{
            System.out.println(a);
            //System.out.println(size);//同变量捕获的注意，要么常量，要么没修改过
        };
        OneParameterNoReturn oneParameterNoReturn2 = a -> System.out.println(a);

        MoreParameterNoReturn moreParameterNoReturn = (a,b)->System.out.println(a+b);
    }

    public static void main1(String[] args) {
        NoParameterNoReturn parameterNoReturn = new NoParameterNoReturn(){
            @Override
            public void test() {
                System.out.println("重写方法！");
            }
        };
        parameterNoReturn.test();

        //lambda表达式写法：
        NoParameterNoReturn parameterNoReturn1 = ()->System.out.println("重写方法！");
        parameterNoReturn1.test();
    }

}